Skip to content

fix(tests): merge vm* dispatcher tests and drop the 0xCCCC dispatcher - #3998

Open
marioevz wants to merge 19 commits into
ethereum:forks/bogotafrom
marioevz:finalize-ported-static-vm
Open

marioevz wants to merge 19 commits into
ethereum:forks/bogotafrom
marioevz:finalize-ported-static-vm

Conversation

@marioevz

@marioevz marioevz commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

Description

Part of finalizing the tests/ported_static/ port. Files are disjoint from the other finalize-ported-static-* PRs, so each can be reviewed and merged independently.

This PR rewrites the VMTests families (vmArithmeticTest, vmBitwiseLogicOperation, vmIOandFlowOperations, vmLogTest, vmTests) and stEIP150singleCodeGasPrices as readable, fork-aware tests:

  • No dispatcher, no pinned addresses. The 0xCCCC DELEGATECALL dispatcher, the d, g, v parametrization, resolve_expect_post, # Source: blocks and pinned addresses are gone. Where a call is part of the subject (RETURN data, environment opcodes, SELFDESTRUCT, gas forwarding), a role-named caller contract replaces it.
  • Readable parameters. Tests are parametrized by meaningful values (offsets, sizes, operands, opcodes, named scenarios) instead of bytecode in pytest.param, and expected values are derived from the parameters: a byte model of memory, an opcode semantics model, keccak256 of the modelled range, and so on.
  • Framework gas only. Gas expectations come from Bytecode.gas_cost(fork), opcode metadata and CodeGasMeasure; hardcoded Cancun/Berlin/EIP-8038 deltas are removed.
  • Fork floors lowered to Frontier in every touched file, using protected=fork.supports_protected_txs(), explicit CALL gas where pre-EIP-150 forwarding matters, per-fork opcode filtering (fork.valid_opcodes(), with_all_call_opcodes, with_all_create_opcodes), and fork predicates for behavioral differences (selfdestruct_deletes_existing_accounts(), selfdestruct_burns_balance(), header_prev_randao_required(), refunds via max_refund_quotient()).
  • Push/calldata axis. Operand-driven tests (jumps, memory, SSTORE/SLOAD, LOG, SHA3, EXP) run with operands as PUSH immediates and as calldata, via a new shared tests/ported_static/helpers.py (Operands, Memory).
  • Sentinels. Result slots start at 0x0BAD, so a zero result or a code path that never runs cannot pass.

Merges

  • vmArithmeticTest: per-opcode files into test_arithmetic.py (one function per opcode, inputs via calldata); test_exp_power2/256/256_of256.py into test_exp_power.py, with the tables generated from a loop.
  • vmBitwiseLogicOperation: per-opcode files into test_bitwise.py.
  • vmIOandFlowOperations: test_mload/mstore/mstore8/msize.py into test_memory.py; test_jumpi.py, test_loops_conditionals.py and test_jump_to_push.py into test_jump.py.
  • vmLogTest: test_log0..4.py into test_log.py.
  • stEIP150singleCodeGasPrices: test_raw_balance_gas, test_raw_ext_code_size_gas, test_raw_ext_code_copy_gas and test_raw_ext_code_copy_memory_gas into test_raw_account_access_gas.py; test_raw_call_gas_ask.py into test_raw_call_gas.py (the fillers differed only in the gas asked).

All original ported_from fillers are still referenced.

Bug fixes and vacuous tests

  • sdiv[sdiv_neg1_minint] deployed its contract at 0x0110 instead of 0x1010, so the dispatcher called an empty account and its zero post was vacuous. It is now test_sdiv[neg1_neg_int_max].
  • mulmod[mm_5_1_0] used data index 0x0d (a copy of mm_1_0_0), so mulmod 5 1 0 never ran. It is now test_mulmod[5_1_0].
  • loop_stacklimit: the filler's dispatcher passed the transaction's value of 1, so loop_1020/loop_1021 looped once and never reached the stack limit, and the post ({0: 0} on an untouched slot) passed without the loop running. The test now derives the counts from fork.max_stack_height(): one loop peaks exactly at the limit and succeeds, the next overflows and fails, and the returned iteration counter is checked.
  • divByZero: asserted 0 with no sentinel, so it passed even if nothing ran.
  • random: only checked the sender nonce; it now checks the call result and the exact gas used.
  • sha3: hashed only zeroed memory, so the offset never affected the result; memory is now pre-filled with a pattern.
  • twoOps: added a negative operand so SMOD and SAR sign handling is exercised.
  • suicide: the myself post passed even if the CALL failed; the CALL result and the receipt gas are now checked.

Other changes from the fillers

  • The three byte-identical jumpi duplicates are removed.
  • msize farChunk writes at 0x200000 instead of 0xB00000: the original offset needs ~254M gas, above the Osaka transaction gas cap and the default block gas limit. The subject (MSIZE rounds to whole words at high offsets) is unchanged.
  • eip2929_oog uses an exact / one-short gas budget pair from gas_cost(fork) instead of the filler's fixed budgets (2000/22000/2500/1750); each old budget sits between the pre- and post-Berlin exact costs, so the "fails from Berlin" meaning is kept.
  • test_raw_call_gas forwards the fillers' original 30000 again (the earlier port forwarded a derived amount), matching their 0x752e/0x7e2a callee readings on Cancun.

The enhance-ported-test skill is updated to match: gas metadata is fork-aware, so it no longer sets a test's floor, and behavioral differences are derived from fork predicates rather than raising valid_from.

Filled from Frontier through Bogota: 50732 passed, 72 frame-unconvertible (cases with an explicit gas limit or state-gas reservoir that frame budgets cannot express).

Related Issues or PRs

N/A.

Checklist

  • Ran fast static checks to avoid CI fails, see Code Standards & Verifying Changes: just static
  • PR title has the form <type>(<area>): <description>, where <type> and <area> come from an appropriate C-<type>, respectively A-<area>, label. The title should match the target squash commit message.

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

@marioevz marioevz added this to the Finalize Ported-Static milestone Nov 14, 2026
@codecov

codecov Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.55%. Comparing base (0063c55) to head (8ef4407).

Additional details and impacted files
@@               Coverage Diff                @@
##           forks/bogota    #3998      +/-   ##
================================================
+ Coverage         95.37%   95.55%   +0.18%     
================================================
  Files               677      677              
  Lines             41907    41907              
  Branches           3939     3939              
================================================
+ Hits              39969    40046      +77     
+ Misses             1359     1319      -40     
+ Partials            579      542      -37     
Flag Coverage Δ
unittests 95.54% <ø> (+0.18%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@spencer-tb spencer-tb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! AI Swarm Review, 3x rotation of 10 fresh agents, findings re-checked by fills, traces and spec mutants, small things inline :)

Checked: every old case against the case it reaches now, the pure cases on an independent EVM, a leading-zero address fill, a full-range fill, and spec mutants of try/catch rules against base.

@danceratopz danceratopz left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Nothing is dropped, the pure refactors are pure, and the fixes are correct. Small findings below and inline, none blocking.

No case dropped: all 2,098 ported_from fillers are still referenced, and on Cancun the 543 old cases map to 557 new ones (3 byte-identical jumpi duplicates removed, jump_to_push 78 to 95). Arithmetic and bitwise targets are byte-identical apart from the two stated fixes, the stEIP150 gas values are unchanged in all 610 fork cases, and of 231 traced cases on Cancun to Osaka the 32 that differ all differ as the commits describe.

My agent ran the same checks as described in the #3997 review.

Main point: the legacy # Source: blocks left in three stEIP150 files, two of them misleading (495 blocks at base, 11 at head, no raw hex left). See the inline comments on test_eip2929.py line 340, test_eip2929_minus_ff.py line 151 and test_gas_cost_memory.py line 541.

Area: PR description
Priority: Minor

The PR body doesn't mention the three removed jumpi duplicates, the farChunk move from 0xB00000 to 0x200000, or the sdiv_neg1_minint and mm_5_1_0 fixes. They are only in the commit messages, which will not survive the squash merge. Could you add a line for each?

Area: clean-up
Priority: Minor

Same kind of clean-up the PR already does, left in the directories it touches. The first two would fit here, the rest could be a follow-up PR.

  • stEIP150singleCodeGasPrices: test_raw_balance_gas.py, test_raw_ext_code_size_gas.py, test_raw_ext_code_copy_gas.py and test_raw_ext_code_copy_memory_gas.py differ only in the measured opcode, so they could be one test parametrized on the opcode.
  • The three stEIP150 files this PR edits still have the docstring Ori Pomerantz qbzzt1@gmail. and each carries its own copy of if_then.
  • vmIOandFlowOperations/test_loop_stacklimit.py still has a DELEGATECALL dispatcher, and its post ({0: 0} on an empty slot) passes without the loop running.
Full list
  • The docstrings are at test_eip2929.py:321, test_eip2929_minus_ff.py:136 and test_gas_cost_memory.py:533.
  • vmArithmeticTest/test_exp_power2.py, test_exp_power256.py and test_exp_power256_of256.py are unrolled tables that a loop over the exponent could generate. test_two_ops.py (1,152 SSTOREs) is the same pattern.
  • Ori Pomerantz qbzzt1@gmail. docstrings also remain in vmArithmeticTest (test_arith.py, test_div_by_zero.py, test_exp_power*.py, test_fib.py, test_two_ops.py) and vmTests/test_random.py.
  • stEIP150singleCodeGasPrices/test_eip2929_oog.py has 12 # Source: lll comments with filler addresses (0xACC7, 0x06A5).
  • vmTests/test_random.py is still the d, g, v parametrization.

@danceratopz danceratopz mentioned this pull request Nov 20, 2026
13 of 27 tasks
@marioevz
marioevz force-pushed the finalize-ported-static-vm branch from 6cbfe88 to bdb4ce2 Compare November 26, 2026 23:52
@marioevz
marioevz marked this pull request as ready for review November 26, 2026 23:59
@marioevz

Copy link
Copy Markdown
Member Author

@danceratopz this is ready for another review and finally get merged :)

@bt-recneps

Copy link
Copy Markdown
Contributor

Ran spec mutants on base and head. The jump, mload OOG, return buffer and codecopy checks miss bugs, and env_info can't land in execute :(

tests/ported_static/vmIOandFlowOperations/test_jump.py:173: No destination lands right after a JUMPDEST, so an off-by-one jumpdest check passes where base jump-not-jumpdest0/1 failed. Add an AFTER_JUMPDEST destination at len(code) + 1.

tests/ported_static/vmIOandFlowOperations/test_memory.py:289: With the offset-0 budget, 0x724825 runs out of gas on linear memory cost alone, so dropping the quadratic term still passes. Give the far reads the filler's 2**24 gas limit.

tests/ported_static/vmTests/test_env_info.py:61: Dropping pre_alloc_mutable un-skipped this module in execute, but every tx pins GAS_PRICE, which is below the Hoodi and mainnet base fee, so none of them can land.

tests/ported_static/vmIOandFlowOperations/test_return.py:110: Caller memory starts zeroed, so a client that zero-pads short return data up to ret_size still passes. Pre-fill the caller's return buffer with SENTINEL and overlay the expected words on it.

tests/ported_static/vmIOandFlowOperations/test_codecopy.py:79: The padding word sits at 0x100, so memory past the code end is already zero and a CODECOPY that skips the zero-fill still passes codecopy_2buff.

tests/ported_static/vmArithmeticTest/test_arithmetic.py:55: Nit: test_arithmetic.py and test_bitwise.py still start at Cancun, unlike every other touched file. With protected=fork.supports_protected_txs() all 24 tests fill from Frontier.

Reviewed in 42m 05s

@danceratopz danceratopz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Mario for the fixes since the last review!

I asked my agent to re-check the new head (case mapping, fixture comparison, traces), with the same method as on #3997, and no cases are dropped. Spencer's mutant findings are all fixed too.

Comments inline.

marioevz and others added 16 commits December 2, 2026 17:23
Merge the five per-opcode files into one test parametrized on topic
count and memory-range scenario (46 cases, ids log<n>-<scenario>).
Each case deploys only its own contract (sentinel in slot 0) and is
called directly, replacing the 0xCCCC... DELEGATECALL dispatcher at
fixed 0x1000+n addresses, so the test no longer needs
pre_alloc_mutable or a custom Environment.

Bug fixed: the old tests only checked the 0x600D completion sentinel
and never asserted the emitted logs. The receipt now asserts address,
topics (including CALLER and PC topics) and data of every log; OOG
cases assert no logs and the untouched sentinel. Mutation check:
appending a byte to the expected data fails 36/46 cases (the 10 OOG
cases emit no log); offsetting the expected topics fails 30/46.

Removed:
- tests/ported_static/vmLogTest/test_log0.py
- tests/ported_static/vmLogTest/test_log1.py
- tests/ported_static/vmLogTest/test_log2.py
- tests/ported_static/vmLogTest/test_log3.py
- tests/ported_static/vmLogTest/test_log4.py
Merge the eleven 0xCCCC... dispatcher files plus the arithmetic NOT
file into test_arithmetic.py, parametrized on the stored expression
and its expected result (ids <family>-<old id>). Each case deploys
only its own contract and is called directly, so pre_alloc_mutable,
the hardcoded 0x1000+n addresses, the fixed sender key, Environment
and the explicit gas limit are gone. Slot 0 is pre-set to a sentinel
so the ~30 cases expecting 0 are no longer satisfied by an untouched
contract. MUL stack underflow becomes its own test asserting the
sentinel survives the exceptional halt.

Bugs fixed:
- sdiv[sdiv_neg1_minint] deployed its contract at 0x0110 instead of
  0x1010, so the dispatcher called an empty account and the zero post
  was vacuous.
- mulmod[mm_5_1_0] used data index 0x0d (a copy of mm_1_0_0), so the
  0x100f contract (mulmod 5 1 0) never ran.
Mutation check: calling an empty account instead of the case contract
fails all 114 table cases, including both fixed ones.

Removed:
- tests/ported_static/vmArithmeticTest/test_add.py
- tests/ported_static/vmArithmeticTest/test_addmod.py
- tests/ported_static/vmArithmeticTest/test_div.py
- tests/ported_static/vmArithmeticTest/test_exp.py
- tests/ported_static/vmArithmeticTest/test_mod.py
- tests/ported_static/vmArithmeticTest/test_mul.py
- tests/ported_static/vmArithmeticTest/test_mulmod.py
- tests/ported_static/vmArithmeticTest/test_not.py
- tests/ported_static/vmArithmeticTest/test_sdiv.py
- tests/ported_static/vmArithmeticTest/test_signextend.py
- tests/ported_static/vmArithmeticTest/test_smod.py
- tests/ported_static/vmArithmeticTest/test_sub.py
Merge the ten 0xCCCC... dispatcher files and test_byte.py into
test_bitwise.py, parametrized on the stored expression and its
expected result (ids <family>-<old id>). Each case deploys only its
own contract and is called directly, so pre_alloc_mutable, the
hardcoded 0x1000+n addresses, the fixed sender key, Environment and
the explicit gas limit are gone. Slot 0 is pre-set to a sentinel so
the 18 cases expecting 0 (and byte_all slot 0) are observable. The
byte_asm raw code and byte_all loop become their own tests; byte_all
stores BYTE(i, ...) for each index in straight-line code.

Mutation check: calling an empty account instead of the case contract
fails all 57 cases.

Removed:
- tests/ported_static/vmBitwiseLogicOperation/test_and.py
- tests/ported_static/vmBitwiseLogicOperation/test_byte.py
- tests/ported_static/vmBitwiseLogicOperation/test_eq.py
- tests/ported_static/vmBitwiseLogicOperation/test_gt.py
- tests/ported_static/vmBitwiseLogicOperation/test_iszero.py
- tests/ported_static/vmBitwiseLogicOperation/test_lt.py
- tests/ported_static/vmBitwiseLogicOperation/test_not.py
- tests/ported_static/vmBitwiseLogicOperation/test_or.py
- tests/ported_static/vmBitwiseLogicOperation/test_sgt.py
- tests/ported_static/vmBitwiseLogicOperation/test_slt.py
- tests/ported_static/vmBitwiseLogicOperation/test_xor.py
blockInfo, envInfo, sha3 and suicide no longer use hardcoded
0x1000+n case contracts behind a 0xCCCC... dispatcher, a fixed sender
key, Environment overrides or explicit gas limits, so none needs
pre_alloc_mutable.

- block_info: call the case contract directly and derive each
  expectation from the Environment; only the PREVRANDAO case sets a
  non-default prev_randao (0x20000) so the read is not vacuous.
- env_info: keep a caller contract (CALLER, CALLVALUE 0x10 and empty
  calldata are the subject) aimed at the case contract. CODECOPY and
  CODESIZE expectations derive from the case bytecode.
- sha3: parametrize on (offset, size); expectations are keccak of the
  zeroed range, the five OOG cases expect the untouched sentinel.
- suicide: keep a caller contract, send to a nonexistent account
  instead of 0xdead, and assert the victim (balance 0, code kept, or
  balance kept for the self-beneficiary) plus the beneficiary's
  balance change. The gas-derived sender balance (patched per fork) is
  dropped as fee bookkeeping.

Slot 0 is pre-set to a sentinel in every case, so the 3 zero-result
envInfo cases and the 5 OOG sha3 cases are no longer vacuous.
Mutation checks: underfunding the envInfo caller fails all 10 cases;
swapping the suicide beneficiaries fails the caller and myself cases.
Merge mload, mstore, mstore8 and msize into test_memory.py,
parametrized on (code, expected storage) with ids <family>-<old id>.
Each case deploys its own contract with the dispatcher's sentinel
(0x0BAD) in slot 0 and is called directly, replacing the 0xCCCC...
DELEGATECALL dispatcher at fixed 0x1000+n addresses, so neither file
needs pre_alloc_mutable or Environment. The tx keeps the original
2**24 gas limit because mloadOOG_2 (MLOAD at 7489573) only runs out of
gas under it.

Bugs fixed:
- msize and gas were valid_until("Prague"): farChunk needed ~254M gas
  for MSTORE8 at 0xB00000 and gas stored the raw GAS value under an
  80M tx. farChunk now writes at 0x200000 (~8.6M gas, same subject:
  MSIZE rounds to whole words at high offsets), and both run on every
  fork from Cancun.
- gas now derives the expected GAS reading from the intrinsic cost and
  the prefix's gas_cost (with memory-expansion metadata) under an
  explicit gas limit, instead of a raw 80M-tx snapshot.
Mutation checks: mis-stating the second MSTORE's memory size fails
gas1; expecting FAR_OFFSET + 64 fails farChunk; dropping the 2**24
limit fails mloadOOG_2 on Cancun and Prague.

Removed:
- tests/ported_static/vmIOandFlowOperations/test_mload.py
- tests/ported_static/vmIOandFlowOperations/test_mstore.py
- tests/ported_static/vmIOandFlowOperations/test_mstore8.py
- tests/ported_static/vmIOandFlowOperations/test_msize.py
Merge jump, jumpi and loopsConditionals into test_jump.py,
parametrized on (code, expected storage) with ids <family>-<label>
(repeated labels numbered). Cases deploy their own contract with the
dispatcher's sentinel in slot 0 and are called directly, so the
0xCCCC... dispatcher, pre_alloc_mutable and Environment are gone.
Three byte-identical duplicates (the JUMPI hyperspace case appears
twice in jumpi and once in jump; not-jump-hyperspace twice in jumpi)
are kept once. The two endless loops move to test_endless_loop with a
bounded gas limit (intrinsic + 100k) instead of burning the full tx.

Bug fixed in jump_to_push: the filler's tx data labels 0x01A..0x19A,
0x20A read hex as decimal, so PUSH26-PUSH31 never ran, no
first-data-byte variant ever ran, the PUSH1 fail case called the
nonexistent 0x1C, and the fail list was duplicated. The test now
generates PUSHn for n in 1..32 jumping after the data (succeeds) or
to the first/last data byte (fails), 95 cases. Mutation check:
expecting success everywhere fails all 63 jump-into-data cases.

Removed:
- tests/ported_static/vmIOandFlowOperations/test_jumpi.py
- tests/ported_static/vmIOandFlowOperations/test_loops_conditionals.py
codecopy, pc, pop, return and sstore_sload no longer deploy case
contracts at fixed 0x1000+n addresses behind a 0xCCCC... dispatcher,
so they need neither pre_alloc_mutable nor Environment.

- codecopy, pc, pop, sstore_sload: call the case contract directly
  with sentinels in the slots the old posts expected to be zero or
  unchanged (the infinite-buffer and pop-underflow failures now
  assert the sentinel). codecopy expectations derive from bytes(code).
- return: keep a DELEGATECALL caller (it reads the callee's return
  data) aimed at the case contract, forwarding all gas.
eip2929, eip2929_minus_ff and gas_cost_memory pinned 0xCA11,
0xCA1100CA11, 0xCA110100, 0xDE57 and 0xBA5E-family addresses because
their measuring contracts are LLL `(if ...)` jump tables with constant
destinations that assume those address push widths. The tables are
now built by an `if_then` helper that derives each JUMPI/JUMP target
from the code length (always PUSH2, as before), so the opcode
sequence and every measured gas value are unchanged while the
addresses are generated. The remaining self-describing literals,
BALANCE(0xCA11) in eip2929 and SELFDESTRUCT(0xDE57) in minus_ff, now
use the deployed addresses. pre_alloc_mutable, Environment and the
hardcoded nonces are dropped.

Checks: with the original addresses the rebuilt eip2929 contract is
byte-identical to the ported one; pinning an address push to PUSH20
keeps all cases green (width independence), while shifting the
derived jump target by one fails all 38 Osaka cases.
Co-authored-by: danceratopz <danceratopz@gmail.com>
marioevz and others added 3 commits December 2, 2026 17:25
@marioevz
marioevz force-pushed the finalize-ported-static-vm branch from 169f9fa to 8ef4407 Compare December 2, 2026 23:45
@marioevz

marioevz commented Dec 2, 2026

Copy link
Copy Markdown
Member Author

@danceratopz applied both your comments, rebased, and also used #4091 helpers to simplify further. I'll merge once CI passes. Thanks!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-tests Area: Consensus tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants